package com.android.personal.kotlin.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.android.personal.kotlin.R;
import com.android.personal.kotlin.greendao.model.UserModel;

import java.util.List;

/**
 * Created by zhangwentao on 2016/12/28.
 */

public class UserAdapter extends BaseAdapter {

    List<UserModel> mUserModelList;
    Context mContext;
    public UserAdapter(Context context) {
        mContext = context;
    }

    public void setUserModelList(List<UserModel> userModelList) {
        mUserModelList = userModelList;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return mUserModelList == null ? 0 : mUserModelList.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.user_list_item, null);
        }
        UserModel userModel = mUserModelList.get(position);
        ((TextView)convertView.findViewById(R.id.name)).setText(userModel.getName());
        ((TextView)convertView.findViewById(R.id.age)).setText(userModel.getAge());
        ((TextView)convertView.findViewById(R.id.sex)).setText(userModel.getSex());
        ((TextView)convertView.findViewById(R.id.height)).setText(userModel.getHeight());
        ((TextView)convertView.findViewById(R.id.weight)).setText(userModel.getWeight());

        return convertView;
    }
}
